package com.fyzk.activity.lottery.gaopin;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan;
import android.view.View;
import android.widget.AbsListView;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.fyzk.activity.app.AppToast;
import com.fyzk.activity.down_numhistory.K3HistoryPrizeView;
import com.fyzk.activity.lottery.shuzicai.BallInfo;
import com.fyzk.activity.lottery.shuzicai.LotteryBaseActivity;
import com.fyzk.activity.lottery.shuzicai.K3SelectBallView;
import com.fyzk.activity.lottery.shuzicai.SelectBallLL;
import com.fyzk.activity.lottery.shuzicai.SelectBallLL.RandomBallListener;
import com.fyzk.activity.lottery.shuzicai.TouZhuHelper;
import com.fyzk.activity.lottery.shuzicai.TouZhuHelper.BallClickListener;
import com.fyzk.activity.lottery.shuzicai.TouZhuHelper.BallItemClickLitener;
import com.fyzk.activity.lottery.shuzicai.klpk.KLPKPopupItemBean;
import com.fyzk.activity.lottery.shuzicai.klpk.KLPKPopupwindow;
import com.fyzk.activity.myview.BallPopFrameLayout;
import com.fyzk.activity.myview.BallScrollView;
import com.fyzk.activity.myview.DrawBallFrameLayout;
import com.fyzk.activity.myview.WeiZhi;
import com.fyzk.activity.trend.K3TrendActivity;
import com.fyzk.bean.PrizeHistoryItem;
import com.fyzk.betcode.AppLotteryCodeListManager;
import com.fyzk.betcode.CodeBase;
import com.fyzk.betcode.CodeFactory;
import com.fyzk.betzhushu.ZhuShuFactory;
import com.fyzk.data.AppLotteryInfos;
import com.fyzk.interfaces.onTopTitleClickListener;
import com.tyjc.lottery.R;
import com.fyzk.utils.HelpUrlConstants;
import com.fyzk.utils.IntentParamUtils;
import com.fyzk.utils.RandomUtil;
import com.fyzk.view.BottomView;
import com.fyzk.view.BottomView.onBottomClickListener;
import com.fyzk.view.TopTitleView;
import com.fyzk.view.ViewCallBack;

import java.util.ArrayList;
import java.util.List;


public abstract class K3Activity extends LotteryBaseActivity implements
        onTopTitleClickListener, onBottomClickListener,
        BallClickListener, BallItemClickLitener, RandomBallListener, KLPKPopupwindow.KLPKPopuponItemListener {

    public static int K3_LOTTERY_ID_INT = 1005;
    public static int K3_LOTTERY_SUMGROUP_ID_INT = 100561;
    public static int K3_LOTTERY_SUMZHI_ID_INT = 100560;//和值
    public static int K3_LOTTERY_ERTONGHAO_DAN_ID_INT = 100510;//二同号单式
    public static int K3_LOTTERY_ERTONGHAO_FU_ID_INT = 100511;//二同号复选
//    public static int K3_LOTTERY_ERTONGHAO_ZU_ID_INT = 100512;//二同号单选组合
    public static int K3_LOTTERY_ERBUTONGHAO_DAN_ID_INT = 100520;//二不同单式
    public static int K3_LOTTERY_ERBUTONGHAO_ZU_ID_INT = 100521;//二不同组合
    public static int K3_LOTTERY_ERBUTONGHAO_TOWED_ID_INT = 100522;//二不同号胆拖
    public static int K3_LOTTERY_SANTONGHAO_ID_INT = 100530;//三同号单式
    public static int K3_LOTTERY_SANBUTONGHAO_DAN_ID_INT = 100540;//三不同单式
    public static int K3_LOTTERY_SANBUTONGHAO_ZU_ID_INT = 100541;//三不同组合
    public static int K3_LOTTERY_SANBUTONGHAO_TOWED_ID_INT = 100542;//三不同胆拖
    public static int K3_LOTTERY_SANTONGHAO_TONG_ID_INT = 100532;//三同号通选
    public static int K3_LOTTERY_SANLIANHAO_TONG_ID_INT = 100550;//三连号通选


    // 顶部
    private TopTitleView topView;
    private int[] popup_itemsId = {R.string.gp_nxk3_he,
            R.string.gp_nxk3_santong, R.string.gp_nxk3_ertong,
            R.string.gp_nxk3_sanbutong, R.string.gp_nxk3_erbutong,
            R.string.gp_nxk3_sanbutong_dan, R.string.gp_nxk3_erbutong_dan,};
    private String[] popup_itemsStr2 = {"奖金","奖金","奖金","奖金","奖金","",""};
    private String[] popup_itemsStr3 = {"9~240米","40~240米","15~80米","10~40米","8米","",""};
//    private String[] popup_items = new String[popup_itemsId.length];
//    private HM_Popupwindow top_popup;
    protected List<KLPKPopupItemBean> popup_items = new ArrayList<>();
    protected KLPKPopupwindow top_popup;

    private TextView endTime_tv;    // 截止时间
    private TextView phase_tv;      // 期号

    // 中间
    private LinearLayout ll_history;
    private SelectBallLL ballLinearLayout;

    private LinearLayout ball_ll_he;
    private LinearLayout ball_ll_sanTong;
    private LinearLayout ball_ll_erTong;
    private LinearLayout ball_ll_sanBuTong;
    private LinearLayout ball_ll_erBuTong;
    private LinearLayout ball_ll_sanBuTongDan;
    private LinearLayout ball_ll_erBuTongDan;

    protected K3SelectBallView ballView_he;
    private CheckBox he_da, he_xiao, he_dan, he_shuang;
    protected K3SelectBallView ballView_sanTong;// 三同号
    private CheckBox sanTongXuan;
    protected K3SelectBallView ballView_erTongDan1;// 二同号单选
    protected K3SelectBallView ballView_erTongDan2;// 二同号单选
    protected K3SelectBallView ballView_erTongFu;// 二同号复选
    protected K3SelectBallView ballView_sanBuTong;// 三不同
    private CheckBox sanLianHao;
    protected K3SelectBallView ballView_erBuTong;// 二不同
    protected K3SelectBallView ballView_sanBuTongDan;//
    protected K3SelectBallView ballView_sanBuTongTuo;//
    protected K3SelectBallView ballView_erBuTongDan;//
    protected K3SelectBallView ballView_erBuTongTuo;//

    private int ball_count_he1 = 16;
    private int ball_count_erTong = 6;
    private List<BallInfo> balls_Line_he = new ArrayList<BallInfo>();
    private List<BallInfo> balls_Line_sanTong = new ArrayList<BallInfo>();
    private List<BallInfo> balls_Line_erTongDan1 = new ArrayList<BallInfo>();
    private List<BallInfo> balls_Line_erTongDan2 = new ArrayList<BallInfo>();
    private List<BallInfo> balls_Line_erTongFu = new ArrayList<BallInfo>();
    private List<BallInfo> balls_Line_sanBuTong = new ArrayList<BallInfo>();
    private List<BallInfo> balls_Line_erBuTong = new ArrayList<BallInfo>();
    private List<BallInfo> balls_Line_sanBuTongDan = new ArrayList<BallInfo>();
    private List<BallInfo> balls_Line_sanBuTongTuo = new ArrayList<BallInfo>();
    private List<BallInfo> balls_Line_erBuTongDan = new ArrayList<BallInfo>();
    private List<BallInfo> balls_Line_erBuTongTuo = new ArrayList<BallInfo>();
    private String[] he_prizes = new String[]{"奖金240米", "奖金80米", "奖金40米",
            "奖金25米", "奖金16米", "奖金12米", "奖金10米", "奖金9米", "奖金9米", "奖金10米",
            "奖金12米", "奖金16米", "奖金25米", "奖金40米", "奖金80米", "奖金240米"};

    private DrawBallFrameLayout ball_linear;
    private BallScrollView ball_scroll;
    private BallPopFrameLayout moveQiu;

    private int wanFaId = K3_LOTTERY_SUMZHI_ID_INT;

    // 底部
    private BottomView bottomView;
    protected LinearLayout shake_random_ll;

    private TextView prizeNum_tv;
    private ImageView prizeNum_iv1, prizeNum_iv2, prizeNum_iv3;
    private LinearLayout prize_ll, prize_Waitting;
    private int[] prizeNum_img_ids = new int[]{R.drawable.dice_v1_small, R.drawable
            .dice_v2_small, R.drawable.dice_v3_small,
            R.drawable.dice_v4_small, R.drawable.dice_v5_small, R.drawable.dice_v6_small};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        setContentView(R.layout.gp_nxk3);
        setLotteryIds();
        wanFaId = K3_LOTTERY_SUMZHI_ID_INT;

        initView();
        ViewCallBack.getInstance().AttachCountDownObj(this);

        top_popup.setCheckItem(popupId);
        topView.setCenterText(getTopTitle() + " - "
                + popup_items.get(popupId).str1);
        // clear();
        popupClickItem(popupId);
        ballClick();

        ballView_he.color_miss_nor = Color.WHITE;
        ballView_sanTong.color_miss_nor = Color.WHITE;
        ballView_erTongDan1.color_miss_nor = Color.WHITE;
        ballView_erTongDan2.color_miss_nor = Color.WHITE;
        ballView_erTongFu.color_miss_nor = Color.WHITE;
        ballView_sanBuTong.color_miss_nor = Color.WHITE;
        ballView_erBuTong.color_miss_nor = Color.WHITE;
        ballView_sanBuTongDan.color_miss_nor = Color.WHITE;
        ballView_sanBuTongTuo.color_miss_nor = Color.WHITE;
        ballView_erBuTongDan.color_miss_nor = Color.WHITE;
        ballView_erBuTongTuo.color_miss_nor = Color.WHITE;

    }

    @Override
    public TopTitleView getTopView() {
        return topView;
    }

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        checkBoxInit();
    }

    /**
     * 初始化LotteryIds
     */
    protected abstract void setLotteryIds();

    private void checkBoxInit() {
        List<BallInfo> da_infos = new ArrayList<BallInfo>();
        List<BallInfo> xiao_infos = new ArrayList<BallInfo>();
        List<BallInfo> dan_infos = new ArrayList<BallInfo>();
        List<BallInfo> shuang_infos = new ArrayList<BallInfo>();
        List<BallInfo> da_dan_infos = new ArrayList<BallInfo>();
        List<BallInfo> da_shuang_infos = new ArrayList<BallInfo>();
        List<BallInfo> xiao_dan_infos = new ArrayList<BallInfo>();
        List<BallInfo> xiao_shuang_infos = new ArrayList<BallInfo>();
        List<BallInfo> infos = new ArrayList<BallInfo>();
        for (int i = 0; i < arr_infos.get(0).size(); i++) {
            BallInfo ballInfo = arr_infos.get(0).get(i);
            int num = 0;
            try {
                num = Integer.parseInt(ballInfo.getNum() + "");
            } catch (Exception e) {
                // TODO: handle exception
            }

            if (ballInfo.isSelected()) {
                infos.add(ballInfo);
            }

            if (i >= (arr_infos.get(0).size() / 2)) {
                da_infos.add(ballInfo);
                if (num % 2 != 0) {
                    da_dan_infos.add(ballInfo);
                } else {
                    da_shuang_infos.add(ballInfo);
                }
            } else {
                xiao_infos.add(ballInfo);
                if (num % 2 != 0) {
                    xiao_dan_infos.add(ballInfo);
                } else {
                    xiao_shuang_infos.add(ballInfo);
                }
            }
            if (num % 2 != 0) {
                dan_infos.add(ballInfo);
            } else {
                shuang_infos.add(ballInfo);
            }
        }
        if (infos.size() > 0) {
            he_da.setChecked(false);
            he_xiao.setChecked(false);
            he_dan.setChecked(false);
            he_shuang.setChecked(false);
            if (isCheckBox(infos, da_infos) || isCheckBox(infos, da_dan_infos)
                    || isCheckBox(infos, da_shuang_infos)) {
                he_da.setChecked(true);
            }
            if (isCheckBox(infos, xiao_infos)
                    || isCheckBox(infos, xiao_dan_infos)
                    || isCheckBox(infos, xiao_shuang_infos)) {
                he_xiao.setChecked(true);
            }
            if (isCheckBox(infos, dan_infos) || isCheckBox(infos, da_dan_infos)
                    || isCheckBox(infos, xiao_dan_infos)) {
                he_dan.setChecked(true);
            }
            if (isCheckBox(infos, shuang_infos)
                    || isCheckBox(infos, da_shuang_infos)
                    || isCheckBox(infos, xiao_shuang_infos)) {
                he_shuang.setChecked(true);
            }
        }

        sanTongXuan.setChecked(balls_Line_sanTong.get(
                balls_Line_sanTong.size() - 1).isSelected());
        sanLianHao.setChecked(balls_Line_sanBuTong.get(
                balls_Line_sanBuTong.size() - 1).isSelected());

    }

    private boolean isCheckBox(List<BallInfo> infos1, List<BallInfo> infos2) {
        if (infos1.size() == infos2.size()) {
            for (int i = 0; i < infos1.size(); i++) {
                if (infos1.get(i).hashCode() != infos2.get(i).hashCode()) {
                    return false;
                }
            }
            return true;
        } else {
            return false;
        }
    }

    protected abstract String getTopTitle();

    private void initView() {
        //顶部
        for (int i = 0; i < popup_itemsId.length; i++) {

            KLPKPopupItemBean itemBean = new KLPKPopupItemBean();
            itemBean.str1 = getString(popup_itemsId[i]);
            itemBean.str2 = popup_itemsStr2[i];
            itemBean.str3 = popup_itemsStr3[i];
            popup_items.add(itemBean);
        }

        top_popup = new KLPKPopupwindow(this, AbsListView.LayoutParams.MATCH_PARENT, AbsListView
                .LayoutParams.WRAP_CONTENT,
                popup_items, 5);
        top_popup.setHm_PopupOnItemListener(this);

        topView = (TopTitleView) findViewById(R.id.gp_nxk3_topTitle);
        topView.setCenterText(getTopTitle() + " - "
                + popup_items.get(0).str1);
        topView.setRightVisible(View.VISIBLE);
        topView.setRightImg(R.drawable.downmenu_icon);
        topView.setRight2Visible(View.VISIBLE);
        topView.getRightImg2().setImageDrawable(getResources().getDrawable(R.drawable.icon_refresh));
        topView.setJianTouVisible(View.VISIBLE);
        topView.setOnTitleClickListener(this);

        endTime_tv = (TextView) findViewById(R.id.k3_endtime_tv);
        phase_tv = (TextView) findViewById(R.id.k3_phase_tv);

        // 中间
        ll_history = (LinearLayout) findViewById(R.id.gp_nxk3_ball_history);

        ball_ll_he = (LinearLayout) findViewById(R.id.gp_nxk3_ll_he);
        ball_ll_sanTong = (LinearLayout) findViewById(R.id.gp_nxk3_ll_santong);
        ball_ll_erTong = (LinearLayout) findViewById(R.id.gp_nxk3_ll_ertong);
        ball_ll_sanBuTong = (LinearLayout) findViewById(R.id.gp_nxk3_ll_sanbutong);
        ball_ll_erBuTong = (LinearLayout) findViewById(R.id.gp_nxk3_ll_erbutong);
        ball_ll_sanBuTongDan = (LinearLayout) findViewById(R.id.gp_nxk3_ll_sanbutong_dan);
        ball_ll_erBuTongDan = (LinearLayout) findViewById(R.id.gp_nxk3_ll_erbutong_dan);
        ballLinearLayout = (SelectBallLL) findViewById(R.id.nxk3_ball_linearlayout);
        ballLinearLayout.setRandomBallListener(this);

        ballView_he = (K3SelectBallView) findViewById(R.id.gp_nxk3_ballview_he1);
        he_da = (CheckBox) findViewById(R.id.gp_nxk3_he_da);
        he_xiao = (CheckBox) findViewById(R.id.gp_nxk3_he_xiao);
        he_dan = (CheckBox) findViewById(R.id.gp_nxk3_he_dan);
        he_shuang = (CheckBox) findViewById(R.id.gp_nxk3_he_shuang);
        ballView_sanTong = (K3SelectBallView) findViewById(R.id.gp_nxk3_ballview_santong);
        sanTongXuan = (CheckBox) findViewById(R.id.gp_nxk3_he_santongxuanchack);
        SpannableString ss = new SpannableString("三同号通选\n开出任意一个豹子即中40米");
        ss.setSpan(new StyleSpan(Typeface.BOLD), 0, 5,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        ss.setSpan(new RelativeSizeSpan(1.0f), 0, 5,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        ss.setSpan(new RelativeSizeSpan(0.5f), 5, ss.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        sanTongXuan.setText(ss);
        ballView_erTongDan1 = (K3SelectBallView) findViewById(R.id.gp_nxk3_ballview_ertong_dan1);
        ballView_erTongDan2 = (K3SelectBallView) findViewById(R.id.gp_nxk3_ballview_ertong_dan2);
        ballView_erTongFu = (K3SelectBallView) findViewById(R.id.gp_nxk3_ballview_ertong_fu);
        ballView_sanBuTong = (K3SelectBallView) findViewById(R.id.gp_nxk3_ballview_sanbutong);
        sanLianHao = (CheckBox) findViewById(R.id.gp_nxk3_sanlianhao);
        ballView_erBuTong = (K3SelectBallView) findViewById(R.id.gp_nxk3_ballview_erbutong);
        ballView_sanBuTongDan = (K3SelectBallView) findViewById(R.id.gp_nxk3_ballview_sanbutong_dan);
        ballView_sanBuTongDan.setSelect_max(2);
        ballView_sanBuTongTuo = (K3SelectBallView) findViewById(R.id.gp_nxk3_ballview_sanbutong_tuo);
        ballView_erBuTongDan = (K3SelectBallView) findViewById(R.id.gp_nxk3_ballview_erbutong_dan);
        ballView_erBuTongDan.setSelect_max(1);
        ballView_erBuTongTuo = (K3SelectBallView) findViewById(R.id.gp_nxk3_ballview_erbutong_tuo);

        initArrayInfos();

        // // 设置关联选球SelectView
        ballView_erTongDan1.setGuanLian_view(ballView_erTongDan2);
        ballView_erTongDan2.setGuanLian_view(ballView_erTongDan1);

        ballView_sanBuTongDan.setGuanLian_view(ballView_sanBuTongTuo);
        ballView_sanBuTongTuo.setGuanLian_view(ballView_sanBuTongDan);

        ballView_erBuTongDan.setGuanLian_view(ballView_erBuTongTuo);
        ballView_erBuTongTuo.setGuanLian_view(ballView_erBuTongDan);
        // ballView_dan.setGuanLian_view(ballView_first);
        // List<K3SelectBallView> guoLian_first = new ArrayList<K3SelectBallView>();
        // guoLian_first.add(ballView_dan);
        // guoLian_first.add(ballView_two);
        // guoLian_first.add(ballView_three);
        // List<K3SelectBallView> guoLian_two = new ArrayList<K3SelectBallView>();
        // guoLian_two.add(ballView_first);
        // guoLian_two.add(ballView_three);
        // List<K3SelectBallView> guoLian_three = new ArrayList<K3SelectBallView>();
        // guoLian_three.add(ballView_first);
        // guoLian_three.add(ballView_two);
        // ballView_first.setGuanLian_view(guoLian_first);
        // ballView_two.setGuanLian_view(guoLian_two);
        // ballView_three.setGuanLian_view(guoLian_three);

        ball_linear = (DrawBallFrameLayout) findViewById(R.id.gp_nxk3_drawball_framelayout);
        ball_scroll = (BallScrollView) findViewById(R.id.gp_nxk3_ballscroll);
        moveQiu = (BallPopFrameLayout) findViewById(R.id.gp_nxk3_fl_moveqiu);
        ball_linear.setScr(ball_scroll);
        ball_linear.setFl_moveqiu(moveQiu);
        ball_linear.setUpOrDownListener(this);

        TouZhuHelper.getInstance().setBallClickListener(this);
        TouZhuHelper.getInstance().setBallItemClickLitener(this);

        he_da.setOnClickListener(this);
        he_xiao.setOnClickListener(this);
        he_dan.setOnClickListener(this);
        he_shuang.setOnClickListener(this);
        sanTongXuan.setOnClickListener(this);
        sanLianHao.setOnClickListener(this);

        // 底部
        bottomView = (BottomView) findViewById(R.id.gp_nxk3_bottom);
        bottomView.setRightText("确定");
        bottomView.setLeftText("清除");
        bottomView.setonBottomClickListener(this);
        bottomView.setMoRenText1(0 + "注 ");
        bottomView.setMoRenText2("共" + 0 + "米");

        shake_random_ll = (LinearLayout) findViewById(R.id.shake_random_ll);
        shake_random_ll.setOnClickListener(this);

//		endTime_tv = (TextView) findViewById(R.id.nxk3_endtime_tv);
//		endTime_qi_tv = (TextView) findViewById(R.id.nxk3_qihao_tv);

        prizeNum_tv = (TextView) findViewById(R.id.nxk3_prizenum_tv);
        prizeNum_iv1 = (ImageView) findViewById(R.id.nxk3_prizenum_iv1);
        prizeNum_iv2 = (ImageView) findViewById(R.id.nxk3_prizenum_iv2);
        prizeNum_iv3 = (ImageView) findViewById(R.id.nxk3_prizenum_iv3);
        prize_ll = (LinearLayout) findViewById(R.id.nxk3_prize_ll);
        prize_Waitting = (LinearLayout) findViewById(R.id.nxk3_prize_waitting);


    }

    @Override
    protected void initArrayInfos() {
        if (arr_infos.size() > 0) {
            balls_Line_he = arr_infos.get(0);
            for (int i = 0; i < balls_Line_he.size(); i++) {
                balls_Line_he.get(i).prize = he_prizes[i];
            }
            balls_Line_sanTong = arr_infos.get(1);
            for (int i = 0; i < balls_Line_sanTong.size(); i++) {
                balls_Line_sanTong.get(i).prize = sanTong_prizes[i];
            }
            balls_Line_erTongDan1 = arr_infos.get(2);
            balls_Line_erTongDan2 = arr_infos.get(3);
            balls_Line_erTongFu = arr_infos.get(4);
            balls_Line_sanBuTong = arr_infos.get(5);
            balls_Line_erBuTong = arr_infos.get(6);
            balls_Line_sanBuTongDan = arr_infos.get(7);
            balls_Line_sanBuTongTuo = arr_infos.get(8);
            balls_Line_erBuTongDan = arr_infos.get(9);
            balls_Line_erBuTongTuo = arr_infos.get(10);
        } else {
            initBallList(balls_Line_he, ball_count_he1, 3, he_prizes);
            initBallListSanTong(balls_Line_sanTong, nums_sanTong,
                    sanTong_prizes);
            initBallListErTong(balls_Line_erTongDan1, nums_erTongDan1);
            initBallListErTong(balls_Line_erTongDan2, nums_erTongDan2);
            initBallListErTong(balls_Line_erTongFu, nums_erTongFu);
            initBallListErTong(balls_Line_sanBuTong, nums_sanBuTong);
            initBallListErTong(balls_Line_erBuTong, nums_erTongDan2);
            initBallListErTong(balls_Line_sanBuTongDan, nums_erTongDan2);
            initBallListErTong(balls_Line_sanBuTongTuo, nums_erTongDan2);
            initBallListErTong(balls_Line_erBuTongDan, nums_erTongDan2);
            initBallListErTong(balls_Line_erBuTongTuo, nums_erTongDan2);

            arr_infos.add(balls_Line_he);
            arr_infos.add(balls_Line_sanTong);
            arr_infos.add(balls_Line_erTongDan1);
            arr_infos.add(balls_Line_erTongDan2);
            arr_infos.add(balls_Line_erTongFu);
            arr_infos.add(balls_Line_sanBuTong);
            arr_infos.add(balls_Line_erBuTong);
            arr_infos.add(balls_Line_sanBuTongDan);
            arr_infos.add(balls_Line_sanBuTongTuo);
            arr_infos.add(balls_Line_erBuTongDan);
            arr_infos.add(balls_Line_erBuTongTuo);
        }

        ballView_he.setBallInfoList(arr_infos.get(0));
        ballView_sanTong.setBallInfoList(balls_Line_sanTong, 6);
        ballView_erTongDan1.setBallInfoList(balls_Line_erTongDan1);
        ballView_erTongDan2.setBallInfoList(balls_Line_erTongDan2);
        ballView_erTongFu.setBallInfoList(balls_Line_erTongFu);
        ballView_sanBuTong.setBallInfoList(balls_Line_sanBuTong, 6);
        ballView_erBuTong.setBallInfoList(balls_Line_erBuTong);
        ballView_sanBuTongDan.setBallInfoList(balls_Line_sanBuTongDan);
        ballView_sanBuTongTuo.setBallInfoList(balls_Line_sanBuTongTuo);
        ballView_erBuTongDan.setBallInfoList(balls_Line_erBuTongDan);
        ballView_erBuTongTuo.setBallInfoList(balls_Line_erBuTongTuo);
    }

    String[] nums_sanTong = new String[]{"111", "222", "333", "444", "555",
            "666", "三同号通选"};
    private String[] sanTong_prizes = new String[]{"奖金240米", "奖金240米",
            "奖金240米", "奖金240米", "奖金240米", "奖金240米", "开出任意一个豹子即中40米"};

    private void initBallListSanTong(List<BallInfo> balls, String[] nums,
                                     String[] prizes) {
        balls.clear();
        for (int j = 0; j < nums.length; j++) {
            BallInfo qiu;
            qiu = new BallInfo(String.valueOf(nums[j]));
            if (prizes.length == nums.length) {
                qiu.prize = prizes[j];
            }
            balls.add(qiu);
        }
    }

    String[] nums_sanBuTong = new String[]{"1", "2", "3", "4", "5", "6",
            "三连号通选"};
    String[] nums_erTongDan1 = new String[]{"11", "22", "33", "44", "55",
            "66"};
    String[] nums_erTongDan2 = new String[]{"1", "2", "3", "4", "5", "6"};
    String[] nums_erTongFu = new String[]{"11*", "22*", "33*", "44*", "55*",
            "66*"};

    private void initBallListErTong(List<BallInfo> balls, String[] nums) {
        balls.clear();
        for (int j = 0; j < nums.length; j++) {
            BallInfo qiu;
            qiu = new BallInfo(String.valueOf(nums[j]));

            balls.add(qiu);
        }
    }

    // ========== popuwindow =================
    @Override
    public void onItem(int position) {

        clear();
        popupClickItem(position);
    }

    @Override
    public void popupShow() {
        topView.setJianTouRotate_shun();

    }

    @Override
    public void popupDismiss() {
        topView.setJianTouRotate_ni();

    }

    // ========== popuwindow =================

    // ========== topTitle =================
    @Override
    public void onLeftClick() {
        onBackPressed();
    }

    @Override
    public void onCenterClick() {
        top_popup.showPopupWindow(topView);
    }

    @Override
    public void onRightClick() {
        toHelp();
    }

    // ========== topTitle =================

    // ========== bottom =================
    @Override
    public void onBottomLeftClick() {
        clear();
    }

    @Override
    public void onBottomRightClick() {
        if (wanFaId == K3_LOTTERY_SANBUTONGHAO_TOWED_ID_INT
                || wanFaId == K3_LOTTERY_ERBUTONGHAO_TOWED_ID_INT) {
            if (getZhushu() < 2) {
                AppToast.getToast().show("胆拖至少选择2注");
                return;
            }
        }
        if (!touZhu()) {
            AppToast.getToast().show("请先选择一注再投注");
        }
    }

    // ========== bottom =================

    @Override
    public boolean touZhu() {
        long zhuShu = getZhushu();
        if (zhuShu > 0) {
            int lotteryId = wanFaId;
            if(wanFaId == K3Activity.K3_LOTTERY_SANTONGHAO_ID_INT ||wanFaId == K3Activity.K3_LOTTERY_SANTONGHAO_TONG_ID_INT){//三同号
                int zhu_sanTongHaoTong = 0;
                if (balls_Line_sanTong.get(balls_Line_sanTong.size() - 1)
                        .isSelected()) {
                    zhu_sanTongHaoTong = 1;
                }
                if (zhuShu - zhu_sanTongHaoTong >= 1) {
                    lotteryId = K3_LOTTERY_SANTONGHAO_ID_INT;
                } else {
                    lotteryId = K3_LOTTERY_SANTONGHAO_TONG_ID_INT;
                }
                touZhu1(lotteryId, zhuShu);
            }else if(
//                    wanFaId ==K3_LOTTERY_ERTONGHAO_ZU_ID_INT ||
                    wanFaId==  K3_LOTTERY_ERTONGHAO_FU_ID_INT || wanFaId == K3_LOTTERY_ERTONGHAO_DAN_ID_INT ){//二同号
                boolean isDanXuan = false;
                int zhuFu = 0;
                for (BallInfo infos : balls_Line_erTongFu) {
                    if (infos.isSelected()) {
                        zhuFu++;
                    }
                }
                isDanXuan = (zhuFu == 0);

                if (isDanXuan) {//单选
                    touZhu1(K3_LOTTERY_ERTONGHAO_DAN_ID_INT,
                            zhuShu, true);
                } else {
                    if (zhuShu - zhuFu != 0) {//单、复混选
                        int wcodeId = K3_LOTTERY_ERTONGHAO_DAN_ID_INT;
                        CodeBase codeObj = CodeFactory.getCode(wcodeId);
                        String Zhuma = codeObj.betCode(arr_infos);
                        String showZhuMa = codeObj.formatHtmlCode2(Zhuma);
                        AppLotteryCodeListManager.getInstance().AddLotteryInfo(
                                wcodeId, Zhuma, showZhuMa, (zhuShu - zhuFu), arr_infos,
                                popupId);
                    }
                    touZhu1(K3_LOTTERY_ERTONGHAO_FU_ID_INT,
                            zhuFu, true);
                }
            }else if(wanFaId == K3_LOTTERY_SANBUTONGHAO_DAN_ID_INT || wanFaId == K3_LOTTERY_SANBUTONGHAO_ZU_ID_INT || wanFaId == K3_LOTTERY_SANLIANHAO_TONG_ID_INT){//三不同
                int zhu_sanLianHao = 0;
                if (balls_Line_sanBuTong.get(balls_Line_sanBuTong.size() - 1)
                        .isSelected()) {
                    zhu_sanLianHao = 1;
                }
                if (zhuShu - zhu_sanLianHao > 1) {
                    lotteryId = K3_LOTTERY_SANBUTONGHAO_ZU_ID_INT;
                } else if (zhuShu - zhu_sanLianHao == 1) {
                    lotteryId = K3_LOTTERY_SANBUTONGHAO_DAN_ID_INT;
                } else {
                    for (int i = 0; i < balls_Line_sanBuTong.size() - 1; i++) {
                        balls_Line_sanBuTong.get(i).setSelected(false);
                    }
                    lotteryId = K3_LOTTERY_SANLIANHAO_TONG_ID_INT;
                }
                touZhu1(lotteryId, zhuShu);
            }else if(wanFaId == K3_LOTTERY_ERBUTONGHAO_DAN_ID_INT||wanFaId == K3_LOTTERY_ERBUTONGHAO_ZU_ID_INT){//二不同
                if (zhuShu > 1) {
                    lotteryId = K3_LOTTERY_ERBUTONGHAO_ZU_ID_INT;
                }
                touZhu1(lotteryId, zhuShu);
            }else {
                touZhu1(lotteryId, zhuShu);
            }

            return true;
        } else {
            return false;
        }

    }

    @Override
    public void clear() {

        bottomView.setMoRenText1(0 + "注 ");
        bottomView.setMoRenText2("共" + 0 + "米");

        balls_LineClear(arr_infos);

        ballView_he.setSelect_count(0);
        ballView_sanTong.setSelect_count(0);
        ballView_erTongDan1.setSelect_count(0);
        ballView_erTongDan2.setSelect_count(0);
        ballView_erTongFu.setSelect_count(0);
        ballView_sanBuTong.setSelect_count(0);
        ballView_erBuTong.setSelect_count(0);
        ballView_sanBuTongDan.setSelect_count(0);
        ballView_sanBuTongTuo.setSelect_count(0);
        ballView_erBuTongDan.setSelect_count(0);
        ballView_erBuTongTuo.setSelect_count(0);

        ballView_he.invalidate();
        he_da.setChecked(false);
        he_xiao.setChecked(false);
        he_dan.setChecked(false);
        he_shuang.setChecked(false);
        ballView_sanTong.invalidate();
        sanTongXuan.setChecked(false);
        ballView_erTongDan1.invalidate();
        ballView_erTongDan2.invalidate();
        ballView_erTongFu.invalidate();
        ballView_sanBuTong.invalidate();
        sanLianHao.setChecked(false);
        ballView_erBuTong.invalidate();
        ballView_sanBuTongDan.invalidate();
        ballView_sanBuTongTuo.invalidate();
        ballView_erBuTongDan.invalidate();
        ballView_erBuTongTuo.invalidate();
    }

    private void balls_LineClear(List<List<BallInfo>> arr) {
        for (int i = 0; i < arr.size(); i++) {
            List<BallInfo> infos = arr.get(i);
            for (BallInfo ballInfo : infos) {
                ballInfo.setSelected(false);
            }
        }
    }

    @Override
    public int getLotteryId() {
        return K3_LOTTERY_ID_INT;
    }

    @Override
    protected void popupClickItem(int arg2) {
        popupId = arg2;
        top_popup.setCheckItem(popupId);
        topView.setCenterText(getTopTitle() + " - "
                + popup_items.get(popupId).str1);
        isYao = true;
        ball_ll_he.setVisibility(View.GONE);
        ball_ll_sanTong.setVisibility(View.GONE);
        ball_ll_erTong.setVisibility(View.GONE);
        ball_ll_sanBuTong.setVisibility(View.GONE);
        ball_ll_erBuTong.setVisibility(View.GONE);
        ball_ll_sanBuTongDan.setVisibility(View.GONE);
        ball_ll_erBuTongDan.setVisibility(View.GONE);

        switch (arg2) {
            case 0:// he
                wanFaId = K3_LOTTERY_SUMZHI_ID_INT;
                ball_ll_he.setVisibility(View.VISIBLE);
                shake_random_ll.setVisibility(View.VISIBLE);
                break;
            case 1:// sanTong
                wanFaId = K3_LOTTERY_SANTONGHAO_ID_INT;
                ball_ll_sanTong.setVisibility(View.VISIBLE);
                shake_random_ll.setVisibility(View.VISIBLE);
                break;
            case 2:// erTong
                wanFaId = K3_LOTTERY_ERTONGHAO_DAN_ID_INT;
                ball_ll_erTong.setVisibility(View.VISIBLE);
                shake_random_ll.setVisibility(View.VISIBLE);
                break;
            case 3:// sanbuTong
                wanFaId = K3_LOTTERY_SANBUTONGHAO_DAN_ID_INT;
                ball_ll_sanBuTong.setVisibility(View.VISIBLE);
                shake_random_ll.setVisibility(View.VISIBLE);
                break;
            case 4:// erbuTong
                wanFaId = K3_LOTTERY_ERBUTONGHAO_DAN_ID_INT;
                ball_ll_erBuTong.setVisibility(View.VISIBLE);
                shake_random_ll.setVisibility(View.VISIBLE);
                break;
            case 5:// sanbuTongDan
                isYao = false;
                wanFaId = K3_LOTTERY_SANBUTONGHAO_TOWED_ID_INT;
                ball_ll_sanBuTongDan.setVisibility(View.VISIBLE);
                shake_random_ll.setVisibility(View.GONE);
                break;
            case 6:// erbuTongDan
                isYao = false;
                wanFaId = K3_LOTTERY_ERBUTONGHAO_TOWED_ID_INT;
                ball_ll_erBuTongDan.setVisibility(View.VISIBLE);
                shake_random_ll.setVisibility(View.GONE);
                break;
            default:
                break;
        }

    }

    @Override
    protected void addHistoryView(ArrayList<PrizeHistoryItem> historyItems, boolean isWaitting) {
        ll_history.removeAllViews();
        K3HistoryPrizeView view = new K3HistoryPrizeView(getContext(), historyItems, isWaitting);
        ll_history.addView(view.getView());

        if (historyItems != null && historyItems.size() > 0) {
            String prizeNum = historyItems.get(0).wincode + "";
            if (!isWaitting && prizeNum != null && prizeNum.contains(",")) {
                prize_Waitting.setVisibility(View.GONE);
                prize_ll.setVisibility(View.VISIBLE);
                String[] prizeNums = prizeNum.split(",");
                int[] prizeId = new int[prizeNums.length];
                for (int i = 0; i < prizeNums.length; i++) {
                    int id = 0;
                    try {
                        id = Integer.parseInt(prizeNums[i]) - 1;
                        prizeId[i] = id;
                    } catch (Exception e) {
                        // TODO: handle exception
                    }
                }
                try {
                    prizeNum_iv1.setImageResource(prizeNum_img_ids[prizeId[0]]);
                    prizeNum_iv2.setImageResource(prizeNum_img_ids[prizeId[1]]);
                    prizeNum_iv3.setImageResource(prizeNum_img_ids[prizeId[2]]);
                    prizeNum_tv.setText((prizeId[0] + 1) + " " + (prizeId[1] + 1) + " " +
                            (prizeId[2] + 1));
                } catch (Exception e) {
                    // TODO: handle exception
                }
            } else {
                prize_Waitting.setVisibility(View.VISIBLE);
                prize_ll.setVisibility(View.GONE);
                prizeNum_tv.setText("- - -");
            }
        }
    }

    @Override
    public void randomBallNum() {
        // TODO Auto-generated method stub
        if (ballLinearLayout.isStarted()) {
            return;
        }
        isYao = false;
        clear();
        List<List<BallInfo>> ballInfos = new ArrayList<List<BallInfo>>();


        if(wanFaId == K3_LOTTERY_SUMZHI_ID_INT){
            randomNum_he();
        }else if(wanFaId == K3_LOTTERY_SANTONGHAO_ID_INT){
            randomNum_sanTong();
        }else if(wanFaId == K3_LOTTERY_ERTONGHAO_DAN_ID_INT){
            randomNum_erTong();
        }else if(wanFaId == K3_LOTTERY_SANBUTONGHAO_DAN_ID_INT){
            randomNum_sanBuTong();
        }else  if(wanFaId == K3_LOTTERY_ERBUTONGHAO_DAN_ID_INT){
            randomNum_erBuTong();
        }
        ballLinearLayout.setLastX(endXs);
        ballLinearLayout.setLastY(endYs);
        ballLinearLayout.setNumId(nums);
        ballLinearLayout.moveStart();

    }

    int[] endXs = new int[3];
    int[] endYs = new int[3];
    int[] nums = new int[3];

    private void randomNum_he() {
        int arr[] = RandomUtil.randomRepeat(3, 0, 6);
        int he = 0;
        int[] endX_Y = new int[2];
        for (int i = 0; i < arr.length; i++) {
            he += (arr[i] + 1);
        }
        for (int i = 0; i < arr_infos.get(0).size(); i++) {
            BallInfo b = arr_infos.get(0).get(i);
            if (b.getNum().equals(he + "")) {
                endX_Y = setEndPosition(b);
            }
        }

        int[] location = new int[2];
        ballView_he.getLocationOnScreen(location);
        int[] location2 = new int[2];
        ballLinearLayout.getLocationOnScreen(location2);
        location2[0] = location[0] - location2[0];
        location2[1] = location[1] - location2[1];

        nums = arr;
        for (int i = 0; i < endXs.length; i++) {
            endXs[i] = endX_Y[0] + location2[0];
            endYs[i] = endX_Y[1] + location2[1];
        }

    }

    private void randomNum_sanTong() {
        int numId = (int) (Math.random() * 6);
        int[] endX_Y = new int[2];
        BallInfo b = balls_Line_sanTong.get(numId);
        endX_Y = setEndPosition(b);

        int[] location = new int[2];
        ballView_sanTong.getLocationOnScreen(location);
        int[] location2 = new int[2];
        ballLinearLayout.getLocationOnScreen(location2);
        location2[0] = location[0] - location2[0];
        location2[1] = location[1] - location2[1];

        for (int i = 0; i < nums.length; i++) {
            nums[i] = numId;
        }
        for (int i = 0; i < endXs.length; i++) {
            endXs[i] = endX_Y[0] + location2[0];
            endYs[i] = endX_Y[1] + location2[1];
        }

    }

    private void randomNum_erTong() {
        int arr[] = RandomUtil.randomNoRepeat(2, 0, 6);
        int[] endX_Y_dan = new int[2];
        int[] endX_Y_dan2 = new int[2];
        BallInfo b = balls_Line_erTongDan1.get(arr[0]);
        endX_Y_dan = setEndPosition(b);
        b = balls_Line_erTongDan2.get(arr[1]);
        endX_Y_dan2 = setEndPosition(b);

        int[] location = new int[2];
        int[] location_shaiZi = new int[2];
        ballLinearLayout.getLocationOnScreen(location_shaiZi);

        int[] location_SelectBall = new int[2];
        ballView_erTongDan1.getLocationOnScreen(location_SelectBall);
        location[0] = location_SelectBall[0] - location_shaiZi[0];
        location[1] = location_SelectBall[1] - location_shaiZi[1];
        endXs[0] = endX_Y_dan[0] + location[0];
        endXs[1] = endX_Y_dan[0] + location[0];
        endYs[0] = endX_Y_dan[1] + location[1];
        endYs[1] = endX_Y_dan[1] + location[1];

        ballView_erTongDan2.getLocationOnScreen(location_SelectBall);
        location[0] = location_SelectBall[0] - location_shaiZi[0];
        location[1] = location_SelectBall[1] - location_shaiZi[1];
        endXs[2] = endX_Y_dan2[0] + location[0];
        endYs[2] = endX_Y_dan2[1] + location[1];

        nums[0] = arr[0];
        nums[1] = arr[0];
        nums[2] = arr[1];
    }

    private void randomNum_sanBuTong() {
        int[] location = new int[2];
        ballView_sanBuTong.getLocationOnScreen(location);
        int[] location2 = new int[2];
        ballLinearLayout.getLocationOnScreen(location2);
        location2[0] = location[0] - location2[0];
        location2[1] = location[1] - location2[1];


        int arr[] = RandomUtil.randomNoRepeat(3, 0, 6);
        int[] endX_Y = new int[2];
        for (int i = 0; i < balls_Line_sanBuTong.size(); i++) {
            for (int j = 0; j < arr.length; j++) {
                if (arr[j] == i) {
                    BallInfo b = balls_Line_sanBuTong.get(i);
                    endX_Y = setEndPosition(b);
                    endXs[j] = endX_Y[0] + location2[0];
                    endYs[j] = endX_Y[1] + location2[1];
                }
            }
        }

        nums = arr;
    }

    private void randomNum_erBuTong() {
        int[] location = new int[2];
        ballView_erBuTong.getLocationOnScreen(location);
        int[] location2 = new int[2];
        ballLinearLayout.getLocationOnScreen(location2);
        location2[0] = location[0] - location2[0];
        location2[1] = location[1] - location2[1];


        int arr[] = RandomUtil.randomNoRepeat(2, 0, 6);
        int[] endX_Y = new int[2];
        for (int i = 0; i < balls_Line_erBuTong.size(); i++) {
            for (int j = 0; j < arr.length; j++) {
                if (arr[j] == i) {
                    BallInfo b = balls_Line_erBuTong.get(i);
                    endX_Y = setEndPosition(b);
                    endXs[j] = endX_Y[0] + location2[0];
                    endYs[j] = endX_Y[1] + location2[1];
                }
            }
        }

        nums = arr;
    }

    private int[] setEndPosition(BallInfo ballInfo) {
        int[] endX_Y = new int[2];
        ballInfo.isChecked = true;
        int left = ballInfo.rect_left;
        int right = ballInfo.rect_right;
        int top = ballInfo.rect_top;
        int bottom = ballInfo.rect_bottom;
        endX_Y[0] = left + (right - left) / 2;
        endX_Y[1] = top + (bottom - top) / 2;
        return endX_Y;
    }

    @Override
    public String getHelpUrl() {
        // TODO Auto-generated method stub
        return HelpUrlConstants.Help_AHK3;
    }

    @Override
    public String getHelpTitle() {
        // TODO Auto-generated method stub
        return getString(R.string.help_anhuik3);
    }

    @Override
    public void ballClick(WeiZhi info) {
        // TODO Auto-generated method stub
        WeiZhi w = info;
        // TODO Auto-generated method stub
        int left = w.getLeft() - 5;
        int right = w.getRight() + 5;
        int top = (int) ((ball_linear.getY1() - w.getPointY() + w.getTop())
                - (w.getBottom() - w.getTop()) - 10);
        int bottom = (int) (ball_linear.getY1() - w.getPointY() + w.getTop());
        Rect rect = new Rect(left, top, right, bottom);
        moveQiu.setRect(rect, w.getNum(), w.getType(), w.isShowMoveBall);
    }

    @Override
    public void ballClick() {
        // TODO Auto-generated method stub
        checkBoxInit();
        long zhushu = getZhushu();
        long money = zhushu * 2;

        bottomView.setMoRenText1(zhushu + "注 ");
        bottomView.setMoRenText2("共" + money + "米");

    }

    private long getZhushu() {
        try {
            return ZhuShuFactory.getZhuShu(wanFaId).betZhuShu(arr_infos);
        } catch (Exception e) {
            return 0;
        }
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        super.onClick(v);
        switch (v.getId()) {
            case R.id.gp_nxk3_he_da:
                if (he_da.isChecked()) {
                    he_xiao.setChecked(false);
                }
                break;
            case R.id.gp_nxk3_he_xiao:
                if (he_xiao.isChecked()) {
                    he_da.setChecked(false);
                }
                break;
            case R.id.gp_nxk3_he_dan:
                if (he_dan.isChecked()) {
                    he_shuang.setChecked(false);
                }
                break;
            case R.id.gp_nxk3_he_shuang:
                if (he_shuang.isChecked()) {
                    he_dan.setChecked(false);
                }
                break;
            case R.id.gp_nxk3_he_santongxuanchack:
                balls_Line_sanTong.get(balls_Line_sanTong.size() - 1).setSelected(
                        sanTongXuan.isChecked());
                break;
            case R.id.gp_nxk3_sanlianhao:
                balls_Line_sanBuTong.get(balls_Line_sanBuTong.size() - 1)
                        .setSelected(sanLianHao.isChecked());
                break;
            case R.id.shake_random_ll:
                randomBallNum();
                break;
            default:
                break;
        }
        kuaiSuHeZhi();
        ballClick();
    }

    /**
     * 和值快速选号
     */
    private void kuaiSuHeZhi() {
        if (arr_infos.get(0) != null && arr_infos.get(0).size() > 0) {
            for (BallInfo b : arr_infos.get(0)) {
                b.setSelected(false);
            }
            List<BallInfo> da_infos = new ArrayList<BallInfo>();
            List<BallInfo> xiao_infos = new ArrayList<BallInfo>();
            List<BallInfo> dan_infos = new ArrayList<BallInfo>();
            List<BallInfo> shuang_infos = new ArrayList<BallInfo>();
            List<BallInfo> infos = new ArrayList<BallInfo>();
            for (int i = 0; i < arr_infos.get(0).size(); i++) {
                BallInfo ballInfo = arr_infos.get(0).get(i);
                int num = 0;
                try {
                    num = Integer.parseInt(ballInfo.getNum() + "");
                } catch (Exception e) {
                    // TODO: handle exception
                }

                if (i >= (arr_infos.get(0).size() / 2)) {
                    da_infos.add(ballInfo);
                } else {
                    xiao_infos.add(ballInfo);
                }
                if (num % 2 != 0 && he_dan.isChecked()) {
                    dan_infos.add(ballInfo);
                }
                if (num % 2 == 0 && he_shuang.isChecked()) {
                    shuang_infos.add(ballInfo);
                }
            }
            if (he_da.isChecked()) {
                infos = da_infos;
            }
            if (he_xiao.isChecked()) {
                infos = xiao_infos;
            }
            if (he_dan.isChecked()) {
                infos = dan_infos;
            }
            if (he_shuang.isChecked()) {
                infos = shuang_infos;
            }

            if (he_da.isChecked() && he_dan.isChecked()) {
                da_infos.retainAll(dan_infos);
                infos = da_infos;
            }
            if (he_da.isChecked() && he_shuang.isChecked()) {
                da_infos.retainAll(shuang_infos);
                infos = da_infos;
            }
            if (he_xiao.isChecked() && he_dan.isChecked()) {
                xiao_infos.retainAll(dan_infos);
                infos = xiao_infos;
            }
            if (he_xiao.isChecked() && he_shuang.isChecked()) {
                xiao_infos.retainAll(shuang_infos);
                infos = xiao_infos;
            }

            for (BallInfo b : infos) {
                b.setSelected(true);
            }

            ballView_he.invalidate();
        }
    }

    @Override
    public void random() {
        // TODO Auto-generated method stub
//		ballView_he.invalidate();
        isYao = true;
        for (int i = 0; i < arr_infos.size(); i++) {
            List<BallInfo> ballInfos = arr_infos.get(i);
            for (int j = 0; j < ballInfos.size(); j++) {
                if (ballInfos.get(j).isChecked) {
                    ballInfos.get(j).setSelected(true);
                }
                ballInfos.get(j).isChecked = false;
            }
        }


        ballView_he.invalidate();
        ballView_sanTong.invalidate();
        ballView_erTongDan1.invalidate();
        ballView_erTongDan2.invalidate();
        ballView_erTongFu.invalidate();
        ballView_sanBuTong.invalidate();
        ballView_erBuTong.invalidate();
        ballView_sanBuTongDan.invalidate();
        ballView_sanBuTongTuo.invalidate();
        ballView_erBuTongDan.invalidate();
        ballView_erBuTongTuo.invalidate();
        ballClick();
    }

    @Override
    protected void net() {
        topView.startRightAnim();
        super.net();
    }

    @Override
    protected boolean setEndAndPhaseText() {
        String endTimeStr = ViewCallBack.getInstance().refreshTimeLeft(
                AppLotteryInfos.getEndTime(getLotteryId()));
        String qi = AppLotteryInfos.getPeriod(getLotteryId());
        try {
            qi = "距" + qi.substring(qi.length() - 2, qi.length()) + "期 截止:";
        } catch (Exception e) {
            // TODO: handle exception
            qi = "距--期 截止:";

        }
        phase_tv.setText(qi);
        endTime_tv.setText(endTimeStr);
        return true;
    }

    @Override
    public Intent getTrendIntent() {
        Intent intent = new Intent(getContext(), K3TrendActivity.class);
        intent.putExtra(IntentParamUtils.LOTTERYID, getLotteryId());
        return intent;
    }
}
